package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chainyoung.common.imageloader.ImageLoader;
import com.chainyoung.common.imageloader.glide.GlideImageConfig;
import com.chainyoung.common.utils.Utils;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.entity.Bank;
import com.chainyoung.component_tmperson.entity.BankItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BankAdapter extends BaseAdapter {

    private Context mContext;
    private List<BankItem> datas;
    private int selectIndex = -1;

    public BankAdapter(Context context, List<BankItem> data) {
        this.mContext = context;
        this.datas = data;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.tmperson_list_bank_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BankItem item = datas.get(position);

        viewHolder.tvName.setText(item.getTitle());

        if (selectIndex == position) {
            viewHolder.ivSelect.setImageResource(R.mipmap.ic_bank_select);
        } else {
            viewHolder.ivSelect.setImageResource(0);
        }

        return convertView;
    }

    public int getSelectIndex() {
        return selectIndex;
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
    }

    static class ViewHolder {
        @BindView(R2.id.tv_name)
        TextView tvName;
        @BindView(R2.id.iv_select)
        ImageView ivSelect;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
